"use strict";
cc._RF.push(module, '02e8exysidL5pCaN9ZseuFq', 'InviteViewUI');
// scripts/InviteViewUI.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("CommonHelper"),
    s = e("nameCfg"),
    l = e("sdkConfig"),
    _ = cc._decorator,
    c = _.ccclass,
    d = _.property,
    h = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.player_node_view = null, t.invite_player_item = null, t.invite_player_view = null, t.match_player_view = null, t.count_down_time = null, t.match_tip_label = null, t.inviter_player = [], t.random_inviter_player = [], t.random_name = [], t.match_random_name = [], t.match_random_hero = [], t.count_down = 0, t.match_over_time = 0, t;
  }

  return nn(t, e), t.prototype.initView = function () {
    e.prototype.initView.call(this), this.match_player_view.active = !1, this.getMatchPlayer(), this.getInvitePlayer();
  }, t.prototype.getMatchPlayer = function () {
    this.inviter_player = [], this.match_random_name = [], n.GlobalParams.MatchGamePlayer = [];
    var e = n.GlobalParams.PlayerInfo.value;
    this.random_name.push(e.name), this.match_random_name.push(e.name), this.inviter_player[0] = {
      name: e.name,
      head: e.head,
      role_id: 0,
      player_skill: [1, 2],
      dower_info: [0, 0],
      level: 1,
      exp_num: 0,
      kill_info: [0, 0, 0],
      skill_info: [0, 0],
      equip_info: [0, 0, 0, 0, 0],
      coin: 0
    }, this.showPlayerView();
  }, t.prototype.showPlayerView = function () {
    for (var e = 0; e < this.player_node_view.childrenCount; e++) {
      var t = this.player_node_view.children[e],
          o = this.inviter_player[e];
      t.getChildByName("player_name").getComponent(cc.Label).string = o ? o.name : "", t.getChildByName("head_image").getComponent(cc.Sprite).spriteFrame = o ? i["default"].getInstance().getHeroHeadFrame("hero_" + o.head) : null, t.getChildByName("my").active = 0 == e, t.getChildByName("player_name").color = 0 == e ? cc.color(20, 255, 50) : cc.color(255, 255, 255);
    }
  }, t.prototype.OnClick = function (t) {
    switch (e.prototype.OnClick.call(this, t), t.node.name) {
      case "back_btn":
        n.GlobalParams.MathcTimeInfo.open = !0, this.node.destroy();
        break;

      case "begin_btn":
        this.match_player_view.active = !0, this.count_down = 1, this.match_over_time = r["default"].getRandomInt(3, 6), this.countDown();
        var o = r["default"].getRandomInt(0, 1);
        n.GlobalParams.MatchMyIndex = o;

        for (var a = 0; a < 6; a++) {
          if (a % 2 == o % 2) {
            var i = a % 2 == 0 ? a / 2 : (a - 1) / 2;
            this.inviter_player[i] ? n.GlobalParams.MatchGamePlayer.push(this.inviter_player[i]) : this.addAIPlayer();
          } else this.addAIPlayer();
        }

        cc.log(this.inviter_player), cc.log(n.GlobalParams.MatchGamePlayer);
    }
  }, t.prototype.getInvitePlayer = function () {
    this.random_inviter_player = [];

    for (var e = 0; e < 10; e++) {
      var t = {
        name: "",
        head: 0,
        level: 0
      },
          o = "";

      do {
        o = l["default"].platform != l.EPlatform.NET_4399 ? s["default"].nameList[r["default"].getRandomInt(0, s["default"].nameList.length - 1)] : "4399玩家" + r["default"].getRandomInt(1e3, 9999);
      } while (-1 != this.random_name.indexOf(o));

      this.random_name.push(o), t.name = o, t.head = r["default"].getRandomInt(1, 15), t.level = n.GlobalParams.PlayerInfo.value.level + r["default"].getRandomInt(-2, 2), this.random_inviter_player.push(t), 9 == e && this.showInvitePlayer();
    }
  }, t.prototype.showInvitePlayer = function () {
    for (var e = 0; e < this.random_inviter_player.length; e++) {
      var t = null;
      this.invite_player_view.children[e] ? t = this.invite_player_view.children[e] : (t = cc.instantiate(this.invite_player_item)).setParent(this.invite_player_view);
      var o = this.random_inviter_player[e];
      t.getChildByName("head_image").getComponent(cc.Sprite).spriteFrame = i["default"].getInstance().getHeroHeadFrame("hero_" + o.head), t.getChildByName("player_name").getComponent(cc.Label).string = "" + o.name, t.getChildByName("level").getComponent(cc.Sprite).spriteFrame = i["default"].getInstance().getPlayerLevelExp(o.level > 28 ? 28 : o.level), t.name = "invite_" + e, t.active = !0, t.getChildByName("invite_btn").on("click", this.invitePlayer, this);
    }
  }, t.prototype.invitePlayer = function (e) {
    var t = e.node;

    if (t.children[0].getComponent(cc.Label).string = "已邀请", t.getComponent(cc.Button).interactable = !1, r["default"].getRandomInt(1, 100) < 70 && this.inviter_player.length < 3) {
      var o = Number(r["default"].getNameType(t.parent.name, "invite_")),
          a = r["default"].getRandomInt(0, 4);
      this.match_random_name.push(this.random_inviter_player[o].name);
      var i = 0;

      do {
        i = n.GlobalParams.GameHeroIndex[r["default"].getRandomInt(0, n.GlobalParams.GameHeroIndex.length - 1)];
      } while (-1 != this.match_random_hero.indexOf(i));

      this.match_random_hero.push(i), this.inviter_player[this.inviter_player.length] = {
        name: this.random_inviter_player[o].name,
        head: this.random_inviter_player[o].head,
        role_id: i,
        player_skill: [1, 2],
        dower_info: [a, n.GlobalParams.PlayerDowerInfo.value.dower[a]],
        level: 1,
        exp_num: 0,
        kill_info: [0, 0, 0],
        skill_info: [1, 0],
        equip_info: [0, 0, 0, 0, 0],
        coin: 0
      }, this.showPlayerView();
    }
  }, t.prototype.countDown = function () {
    var e = this;
    this.count_down_time.string = "" + this.count_down, this.match_tip_label.string = "正在匹配";

    for (var t = 0; t < 3; t++) {
      t < this.count_down % 4 && (this.match_tip_label.string += "。");
    }

    this.count_down < this.match_over_time ? cc.tween(this.count_down_time.node).to(0.8, {
      scale: 1
    }).delay(0.2).call(function () {
      e.count_down_time.node.scale = 0.1, e.count_down++, e.countDown();
    }).start() : (this.uiManager.showPopup("ChooseHoreViewUI"), this.node.destroy());
  }, t.prototype.addAIPlayer = function () {
    var e = "";

    do {
      e = l["default"].platform != l.EPlatform.NET_4399 ? s["default"].nameList[r["default"].getRandomInt(0, s["default"].nameList.length - 1)] : "4399玩家" + r["default"].getRandomInt(1e3, 9999);
    } while (-1 != this.match_random_name.indexOf(e));

    this.match_random_name.push(e);
    var t = 0;

    do {
      t = n.GlobalParams.GameHeroIndex[r["default"].getRandomInt(0, n.GlobalParams.GameHeroIndex.length - 1)];
    } while (-1 != this.match_random_hero.indexOf(t));

    this.match_random_hero.push(t);
    var o = r["default"].getRandomInt(0, 4),
        a = {
      name: e,
      head: l["default"].platform != l.EPlatform.NET_4399 ? r["default"].getRandomInt(1, 19) : r["default"].getRandomInt(1, 9),
      role_id: t,
      player_skill: [1, 2],
      dower_info: [o, n.GlobalParams.PlayerDowerInfo.value.dower[o]],
      level: 1,
      exp_num: 0,
      kill_info: [0, 0, 0],
      skill_info: [1, 0],
      equip_info: [0, 0, 0, 0, 0],
      coin: 0
    };
    n.GlobalParams.MatchGamePlayer.push(a);
  }, oo([d(cc.Node)], t.prototype, "player_node_view", void 0), oo([d(cc.Node)], t.prototype, "invite_player_item", void 0), oo([d(cc.Node)], t.prototype, "invite_player_view", void 0), oo([d(cc.Node)], t.prototype, "match_player_view", void 0), oo([d(cc.Label)], t.prototype, "count_down_time", void 0), oo([d(cc.Label)], t.prototype, "match_tip_label", void 0), oo([c], t);
}(a["default"]);

o["default"] = h;

cc._RF.pop();